package com.huike.report.mapper;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.Page;
import com.huike.clues.domain.dto.ReportDto;
import com.huike.clues.domain.vo.ClueReportVo;
import com.huike.contract.domain.vo.BusinesschangeVO;
import com.huike.report.domain.DTO.PageDTO;
import com.huike.report.domain.vo.ActivityStatisTicVO;
import com.huike.report.domain.vo.ActivityStatisticsVo;
import com.huike.report.domain.vo.ChanelStatisticsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

/**
 * 首页统计分析的Mapper
 *
 * @author Administrator
 */
@Service
@Mapper
public interface ReportMapper {



    /**=========================================基本数据========================================*/


    /**
     * =========================================基本数据========================================
     */
    Integer cluesNum(Map map);

    Integer businessNum(Map map);

    Integer contractNum(Map map);

    Double salesAmount(HashMap<String, Object> map);

    @Select("select count(*) from tb_clue where status =1 or status = 2 or status = 6")
    Integer effectiveCluesNums(HashMap<String, Object> map);

    /**
     * =========================================今日简报========================================
     *
     * @return
     */
    Integer todayCluesNum(HashMap<String, Object> map);
    /**
     * 查询总用户数量和新增用户数量
     * @param map
     * @return
     */
    Integer userStatistics(HashMap<String, Object> map);

    Page<ClueReportVo> page(ReportDto reportDto);

    /**=========================================基本数据========================================*/
    /**
     * 活动统计饼状图
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    List<ActivityStatisTicVO> activityStatisTice(LocalDate beginCreateTime, LocalDate endCreateTime);

    /**
     * 活动统计饼状图
     * @param activityId
     * @return
     */
    @Select("select count(*) as num from tb_clue where activity_id=#{activityId} group by activity_id")
    Integer clueById(Long activityId);

//    Page<ActivityStatisticsVo> page(PageDTO pageDTO);



    @Select("select count(activity_id) from tb_clue where activity_id=#{activityByid} group by activity_id")
    Integer clueactivityById(Long activityByid);
    @Select("select count(false_count) from tb_clue where activity_id=#{activityByid} and status=4  group by activity_id")
    Integer falseClues(Long activityByid);
    @Select("select count(activity_id) from tb_clue where activity_id=#{activityByid} and status=6 group by activity_id")
    Integer businessNumById(Long activityByid);
    @Select("select count(activity_id) from tb_business where activity_id=#{activityByid} and status=7 group by activity_id")
    Integer customersNumById(Long activityByid);

    @Select("select sum(contract_order) from tb_contract where activity_id=#{activityByid} group by activity_id ")
    Double amount(Long activityByid);
    @Select("select sum(course_price) from tb_contract where activity_id=#{activityByid} group by activity_id")
    Double cost(Long activityByid);

    Page<ActivityStatisticsVo> actPage(PageDTO pageDTO);


    /**=========================================基本数据========================================*/

    Integer todayBusinessNum(HashMap<String, Object> map);

    Integer todayContractNum(HashMap<String, Object> map);

    Double todaySalesAmount(HashMap<String, Object> map);


    /**
     * =========================================待办========================================
     */
    Integer tofollowedCluesNum(HashMap<String, Object> map);

    Integer tofollowedBusinessNum(HashMap<String, Object> map);

    @Select("select count(*) from tb_clue where id not in (select assign_id from tb_assign_record where type = 0)")
    Integer toallocatedCluesNum(HashMap<String, Object> map);

    @Select("select count(*) from tb_clue where id not in (select assign_id from tb_assign_record where type = 1)")
    Integer toallocatedBusinessNum(HashMap<String, Object> map);



    List<ChanelStatisticsVo> chanelStatistics(@Param("beginCreateTime") LocalDate beginCreateTime, @Param("endCreateTime") LocalDate endCreateTime);

    @Select("select dict_label as channel from sys_dict_data where dict_value = #{channel} and dict_type ='clues_item'  ")
    String onlineType(String channel);

    /**
     * 商机转换龙虎榜
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    Integer getById(@Param("beginCreateTime") String beginCreateTime,@Param("endCreateTime") String endCreateTime);

    List<BusinesschangeVO> getlist(@Param("beginCreateTime")String beginCreateTime, @Param("endCreateTime") String endCreateTime);


    /**
     * 线索转换龙虎榜
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    List<BusinesschangeVO> getVOlist(@Param("beginCreateTime") String beginCreateTime,@Param("endCreateTime") String endCreateTime);

    int getclue( @Param("beginCreateTime")String beginCreateTime,@Param("endCreateTime") String endCreateTime);
}
